// Ofri Keidar 302933981 group 05

package model.apartment;

import java.util.Map;

/**
 * The class represents a penthouse, inherits from class Apartment 
 */
public class Penthouse extends Apartment {

	/**
	 * Checks that the parameters for a new penthouse are of correct format 
	 */
	public static class PenthouseParametersChecker extends ParameterChecker {
		
		/**
		 * Parses common apartment's parameters using base class's checker 
		 * and checks the rest of the parameters 
		 */
		public boolean parseParameters(Map<String, String> parameters) {
			
			// check if value given for each penthouse parameter
			if (parameters.get(FLOOR) == null || parameters.get(BALCONY_AREA) == null) {
				
				return false;
			}
			
			// check basic parameters correctness
			if (!super.parseParameters(parameters)) {
				
				// basic extraction went wrong, stop parsing
				return false;
			}
			
			try {

				// check if value given for floor is a positive integer value				
				double checkNumericValue = Integer.parseInt(parameters.get(FLOOR));
				if (checkNumericValue <= 0) {
					// floor cannot be non-positive
					return false;
				}	
				
				// check if value given for storage area is a non-negative numeric value
				checkNumericValue = Double.parseDouble(parameters.get(BALCONY_AREA));
				if (checkNumericValue < 0) {
					// extra unit size cannot be negative
					return false;
				}
	
				// parameters are of correct format
				return true;
				
			} catch (NumberFormatException e) {
				// at least one of numeric parameters was not inserted correctly
				return false;
			}
		}
	}
	
	/**
	 * Constructor- initializes a new penthouse using given values
	 * @param floor- penthouse's floor
	 * @param roomNum- penthouse's room number
	 * @param size- penthouse's size
	 * @param balcony- penthouse's balcony size
	 * @param resName- penthouse's resident name
	 * @param apartmentNum- apartment's number in building
	 * @param bldID- apartment's building ID
	 * @param address- apartment's building address
	 */
	public Penthouse(int floor, double roomNum, double size, double balcony,
			String resName, int apartmentNum, int bldID, String address) {
		// initialize attributes according to given values
		super(floor, roomNum, size, balcony ,resName, apartmentNum, bldID, address); // use base class's constructor
	}
		
	/**
	 * Constructor- initializes a new penthouse using given values. Used when no resident name is given
	 * @param floor- penthouse's floor
	 * @param roomNum- penthouse's room number
	 * @param size- penthouse's size
	 * @param balcony- penthouse's balcony size
	 */
	public Penthouse(int floor, double roomNum, double size, double balcony) {
		// initialize attributes according to given values
		super(floor, roomNum, size, balcony); // use base class's constructor
	}
	
	/**
	 * Returns balcony size, using base class's extra unit getter 
	 * @return- balcony size
	 */
	public double getBalconySize() { return getExtraUnit(); }
	
	/**
	 * Sets balcony as given value
	 * @param newSize- new size for balcony
	 */
	public void setBalconySize(double newSize) { setExtraUnit(newSize); }
	
	/**
	 * Calculates penthouse's total area as sum of penthouse's size and balcony 
	 */
	public double totalArea() {
		// sum size and balcony area and return result
		return getSize() + getExtraUnit(); 
	}
		
	/**
	 * Returns penthouse's printing format (as a String object) using base class's toString() 
	 */
	public String toString() {
		// use Apartment class's string format to create output
		return "Type: penthouse, " + super.toString();
	}
}